//碰撞（无摩擦）

var iSpeedX = 20;
var iSpeedY = 20;

function doMove(obj){
	var xMax = document.documentElement.clientWidth - obj.offsetWidth;
	var yMax = document.documentElement.clientHeight - obj.offsetHeight;
	
	clearInterval(obj.timer);
	obj.timer = setInterval(function (){
		var x = obj.offsetLeft + iSpeedX;
		var y = obj.offsetTop + iSpeedY;

		if (y > yMax) {
			iSpeedY *=-1;
			y = yMax;		//使其一瞬间不会有滚动条出现碰撞
		};
		if (x > xMax) {
			iSpeedX *=-1;
			x = xMax;
		};
		if (y < 0) {
			iSpeedY *=-1;
		};
		if (x < 0) {
			iSpeedX *=-1;
		};

		obj.style.left = x + 'px';
		obj.style.top = y + 'px';
	},30)
};